<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <!-- <el-form-item label="反馈类型 0:意见反馈 1:问题提问" prop="backType">
      <el-input v-model="dataForm.backType" placeholder="反馈类型 0:意见反馈 1:问题提问"></el-input>
    </el-form-item>
    <el-form-item label="意见反馈时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="意见反馈时间"></el-input>
    </el-form-item>
    <el-form-item label="反馈人ID" prop="backUserId">
      <el-input v-model="dataForm.backUserId" placeholder="反馈人ID"></el-input>
    </el-form-item>
    <el-form-item label="返回人用户类型" prop="backUserType">
      <el-input v-model="dataForm.backUserType" placeholder="返回人用户类型"></el-input>
    </el-form-item>
    <el-form-item label="反馈人名称" prop="backUserName">
      <el-input v-model="dataForm.backUserName" placeholder="反馈人名称"></el-input>
    </el-form-item>
    <el-form-item label="反馈人手机号" prop="backUserMobile">
      <el-input v-model="dataForm.backUserMobile" placeholder="反馈人手机号"></el-input>
    </el-form-item>
    <el-form-item label="反馈人内容" prop="backContent">
      <el-input v-model="dataForm.backContent" placeholder="反馈人内容"></el-input>
    </el-form-item>
    <el-form-item label="反馈图片地址,多张使用逗号(,)隔开" prop="backImageUrl">
      <el-input v-model="dataForm.backImageUrl" placeholder="反馈图片地址,多张使用逗号(,)隔开"></el-input>
    </el-form-item>
    <el-form-item label="回复人用户ID" prop="replyUserId">
      <el-input v-model="dataForm.replyUserId" placeholder="回复人用户ID"></el-input>
    </el-form-item>
    <el-form-item label="回复人用户名称" prop="replyUserName">
      <el-input v-model="dataForm.replyUserName" placeholder="回复人用户名称"></el-input>
    </el-form-item>
    <el-form-item label="回复时间" prop="replyTime">
      <el-input v-model="dataForm.replyTime" placeholder="回复时间"></el-input>
    </el-form-item>
    <el-form-item label="回复内容" prop="replyContent">
      <el-input v-model="dataForm.replyContent" placeholder="回复内容"></el-input>
    </el-form-item>
    <el-form-item label="回复图片地址,多张使用逗号(,)隔开" prop="replyImageUrl">
      <el-input v-model="dataForm.replyImageUrl" placeholder="回复图片地址,多张使用逗号(,)隔开"></el-input>
    </el-form-item>
    <el-form-item label="回复状态" prop="backState">
      <el-input v-model="dataForm.backState" placeholder="回复状态"></el-input>
    </el-form-item> -->
    <el-form-item label="反馈类型" prop="backType">
      <span>{{dataForm.backType === '0' ? '意见反馈' : '问题提问'}}</span>
    </el-form-item>
    <el-form-item label="反馈内容" prop="backContent">
      <el-input type="textarea" v-model="dataForm.backContent" placeholder="反馈内容"></el-input>
    </el-form-item>
    <el-form-item label="回复内容" prop="replyContent">
      <el-input type="textarea" v-model="dataForm.replyContent" placeholder="回复内容"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          backId: 0,
          backType: '',
          backContent: '',
          replyContent: ''
        },
        dataRule: {}
      }
    },
    methods: {
      init (id) {
        this.dataForm.backId = 0
        this.dataForm.backType = ''
        this.dataForm.backContent = ''
        this.dataForm.replyContent = ''
        this.dataForm.backId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.backId) {
            this.$http({
              url: this.$http.adornUrl(`/feedback/getFeedbackInfoById/${this.dataForm.backId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.backType = data.data.backType
                this.dataForm.backContent = data.data.backContent
                this.dataForm.replyContent = data.data.replyContent
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/feedback/modifyFeedbackById`),
              method: 'post',
              data: this.$http.adornData({
                'backId': this.dataForm.backId || undefined,
                'backContent': this.dataForm.backContent,
                'replyContent': this.dataForm.replyContent
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
